package com.java1412.controller;

import cn.com.webxml.ArrayOfString;
import cn.com.webxml.WeatherWS;
import cn.com.webxml.WeatherWSSoap;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author java1412
 * @create 2021-07-16 13:33
 */
@Slf4j
@RestController
public class WeatherController {

    @GetMapping(value = "/weather")
    public List<String> getWeather() {
        WeatherWSSoap weatherWSSoap = new WeatherWS().getWeatherWSSoap();
        // 获取国家信息
        ArrayOfString arrayOfString = weatherWSSoap.getRegionCountry();
        List<String> list = arrayOfString.getString();
        for (String result : list) {
            log.warn(result);
        }
        // 获取省份
        ArrayOfString arrayOfString1 = weatherWSSoap.getRegionProvince();
        List<String> list1 = arrayOfString1.getString();
        for (String s : list1) {
            log.warn(s);
        }

        // 获取城市——北京
        ArrayOfString arrayOfString2 = weatherWSSoap.getSupportCityString("311101");
        List<String> list2 = arrayOfString2.getString();
        for (String s : list2) {
            log.warn(s);
        }

        // 注意：获取天气需要账号userid，每天可以免费试用5次，随便注册一个账号测试就可以
        // 1944:南京的城市编码
        ArrayOfString arrayOfString3 = weatherWSSoap.getWeather("1944", "ee447644c2c2481cb71177c853fabf7e");
        List<String> list3 = arrayOfString3.getString();
        for (String s : list3) {
            log.warn(s);
        }
        return list3;
    }
}
